<%inherit file="base.html"/>

<%def name="head()">
<link href="/static/uploadify/uploadify.css" rel="stylesheet">
<script src="/static/uploadify/jquery.uploadify.min.js"></script>
<script>
    $(function () {
        $('#file_upload').uploadify({
            'buttonText': '上传数据文件',
            'formData': {'_xsrf': ''},
            'fileSizeLimit': '200MB',
            'fileTypeExts': '*.gz',
            'swf': '/static/uploadify/uploadify.swf',
            'uploader': '/backup/upload',
            'onUploadSuccess': function (file, data, response) {
                window.location.reload();
            }
        });
    });
</script>
<script>
function dumpdb(){
    $.get("/backup/dump", {}, function (ev) {
        console.log(ev);
        console.log(ev.msg);
        window.location.reload();
        alert(ev.msg);
    }, "json");
}

function restoredb(bakfs){
    if (!confirm("确认恢复操作吗？")) {
        return;
    }
    $.post("/backup/restore", {bakfs:bakfs}, function (ev) {
        console.log(ev);
        console.log(ev.msg);
        window.location.reload();
        alert(ev.msg);
    }, "json");
}

function deletefs(bakfs){
    if (!confirm("确认删除操作吗，此操作不可恢复？")) {
        return;
    }
    $.post("/backup/delete", {bakfs:bakfs}, function (ev) {
        console.log(ev);
        console.log(ev.msg);
        window.location.reload();
        alert(ev.msg);
    }, "json");
}
</script>
</%def>

<%def name="body()">
<section class="content">
    <div class="box">
    <div class="panel-heading"><i class="fa fa-database"></i> 数据库备份管理</div>
    <div class="panel-body">
        <form id="query_form" class="form-horizontal form-well" role="form" action="/ops/opslog" method="post">
            <div class="form-group">
                <label for="operator_name" class="col-md-4 control-label">备份目录</label>
                <div class="col-md-4">
                    <input type="text" id="backup_path" name="backup_path" class="form-control" value="${backup_path}" readonly="readonly">
                </div>           
                <div class="col-md-4">
                    <button type="button" onclick="dumpdb();" class="btn btn-primary">立即备份</button>
                </div>

            </div>   
        </form>

        <div class="well">
            <button id="file_upload" type="button" class="btn btn-lg btn-primary">上传备份</button>
        </div>

        <table class="table table-hover">
            <thead>
            <tr>
                <th width="60%">备份名称</th>
                <th width="40%">操作</th>
            </tr>
            </thead>
            <tbody>
            % for backup in backups:
            <tr>
                <td>${backup}</td>
                <td>
                    <a href="javascript:deletefs('${backup}')">删除</a> | 
                    <a href="/backup/download/${backup}">下载</a> | 
                    <a href="javascript:restoredb('${backup}')">恢复</a>
                </td>
            </tr>
            % endfor
            </tbody>
        </table>
    </div>
</div>
</section>

</%def>
